//初始化函数
function just() {
    const n = $('.poster-item').length;
    let MaxIndex = Math.floor(n/2);
    //posterItem个数为偶数时
    if(n%2===0){
        for(let i =0;i<=Math.floor(n/2);i++){
            $(".poster-item")[i].style.zIndex = MaxIndex;
            MaxIndex--;
        };
        MaxIndex=1;
        for (let j = Math.floor(n/2)+1;j<=n-1;j++){
            $(".poster-item")[j].style.zIndex = MaxIndex;
            MaxIndex++;
        };
    }else{
        for(let i =0;i<=Math.floor(n/2);i++){
            $(".poster-item")[i].style.zIndex = MaxIndex;
            MaxIndex--;
        };
        MaxIndex=0;
        for (let j = Math.floor(n/2)+1;j<=n-1;j++){
            $(".poster-item")[j].style.zIndex = MaxIndex;
            MaxIndex++;
        };
    }
    $(function(){Carousel.init($(".J_Poster"));});
}
//jsonp
function jsonp(url,cbfn) {
    var re =/callback=([^&]+)/;
    var fnName = url.match(re)[1];
    var script = document.createElement('script');
    script.src=url;
    document.body.append(script);
    window[fnName]=cbfn;
    script.onload =function(){
        this.remove();
    };
}
//WINDOW加载执行添加+初始化
this.onload=function () {
    let countLi = localStorage.getItem("newPoster");
    let Url =   localStorage.getItem("URL");
    let PosterNum = $('.poster-item').length;
    // 更换网页资源此处需要修改const headurl = "https://asset1.vincicar.cn/";
    const headurl = "https://asset1.vincicar.cn/";
    // for(let i =0;i<countLi;i++){
    //     let PosterNum = $('.poster-item').length;
    //     $($('.poster-item')[0]).clone().appendTo('.poster-list');
    //     jsonp('https://carw.vincicar.com/vb/asset/wp_list?callback=fun' + i, 'fun' + i,function (data) {
    //         //"assets"需要根据网页json属性进行更改
    //         let URL = headurl.concat(data.assets[i].src);
    //         $('.poster-item>img')[PosterNum].src = URL;
    //     })
    // }
    for(let i =0;i<countLi;i++){
        $($('.poster-item')[0]).clone().appendTo('.poster-list');
    }
    jsonp('https://carw.vincicar.com/vb/asset/wp_list?callback=fun' ,function (data) {
        //"assets"需要根据网页json属性进行更改
        console.log(countLi)
        const MaxArray = data.assets.length;
        let SrcArray = [];
        for(let i =0;i<MaxArray;i++){
            let URL = headurl.concat(data.assets[i].src);
            SrcArray[i] = URL;
        }
        for(let j=0;j<countLi;j++){
            let URL= SrcArray[j];
            $('.poster-item>img')[PosterNum+j].src = URL;
        }
    })
    just();
}




